// src/utils/errors.ts
export class AppError extends Error {
  public code: number; // HTTP 状态码
  public data?: any; // 额外错误信息
  public isOperational: boolean;

  constructor(message: string, code: number, data?: any) {
    super(message);
    this.code = code;
    this.data = data;
    this.isOperational = true;
    Error.captureStackTrace(this, this.constructor);
  }
}

// 常见错误类型
export class BadRequestError extends AppError {
  constructor(message: string = "Bad Request", data?: any) {
    super(message, 400, data);
  }
}

export class UnauthorizedError extends AppError {
  constructor(message: string = "Unauthorized", data?: any) {
    super(message, 401, data);
  }
}

export class ForbiddenError extends AppError {
  constructor(message: string = "Forbidden", data?: any) {
    super(message, 403, data);
  }
}

export class NotFoundError extends AppError {
  constructor(message: string = "Not Found", data?: any) {
    super(message, 404, data);
  }
}

export class InternalServerError extends AppError {
  constructor(message: string = "Internal Server Error", data?: any) {
    super(message, 500, data);
  }
}
